// Client

AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

// Include

include('shared.lua')

// Initialize

function ENT:Initialize()
	self.Entity:SetModel("models/props_lab/jar01a.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:SetUseType(ONOFF_USE)
	self.Entity:DrawShadow(false)
	self.Entity:SetNetworkedInt(0, 0)
	
	// Point
	
	self.Entity:SetNetworkedInt("X", X)
	self.Entity:SetNetworkedInt("Y", Y)
	self.Entity:SetNetworkedInt("Z", Z)
	
	// Collision bounds
	
	local Minimum = Vector(-X, -Y, -Z)
	local Maximum = Vector(X, Y, Z)
	
	self.Entity:SetCollisionBounds(Minimum, Maximum)
end

// Think

function ENT:Think()
	// X, Y and Z
	
	local X = self.Entity:GetNetworkedInt("X")
	local Y = self.Entity:GetNetworkedInt("Y")
	local Z = self.Entity:GetNetworkedInt("Z")
	
	// Owner
	
	local Owner = self.Entity:GetPlayer()
	
	// Maximum
	
	local Minimum = self.Entity:GetPos()
	local Maximum = Vector(Minimum.x + X, Minimum.y + Y, Minimum.z + Z)
	
	// Find in box
	
	local Entities = ents.FindInBox(Minimum, Maximum)
	
	// Loop through all found entities
	
	for K, V in pairs(Entities) do
		local Player = V:IsPlayer()
		
		if (Player) then
			if (V != Owner) then
				local Velocity = V:GetVelocity()
				
				V:SetMoveType(MOVETYPE_WALK)
				V:SetVelocity(Velocity * -25)
				
				// Sound
				
				V:EmitSound("weapons/fx/rics/ric4.wav")
			end
		end
	end
end